/**   
* @Title: ReportController.java 
* @Package com.kerrykidz.system.controller 
* @Description: 
* Copyright: Copyright (c) 2014 
* Company:wuwh team by iss
* @author: as   
* @date: 2014年9月11日 上午10:50:13 
* @version: V1.0
*
*/
package com.kerrykidz.system.controller;

import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kerrykidz.system.service.IReportService;
import com.kerrykidz.system.util.DateUtil;
import com.kerrykidz.system.util.UserUtil;
import com.kerrykidz.system.vo.ReportSearchParam;
import com.kerrykidz.system.vo.UserInfo;
import com.rdp.framework.exception.RDPException;

/**
 * 
 * @ClassName: ReportController 
 * @description: 报表的相关
 * @author: zhuss 
 * @date: 2014年9月11日 上午10:58:01 
 * @version: V1.0
 *
 */
@Controller
@RequestMapping("/report")
public class ReportController {
	
	@Autowired
	private IReportService reportService;

	/**
	 * 用于非分页查询以及跳转页面
	 * @param key
	 * @param model
	 * @param reportParam
	 * @return
	 * @throws RDPException
	 * @date: 2014年10月23日
	 */
	 @RequestMapping(value="/jump",method=RequestMethod.GET)
	 public String jump(String key,ModelMap model,ReportSearchParam reportParam)throws RDPException{
		 UserInfo user = UserUtil.getUserFromSession();
		 if(StringUtils.isBlank(key))
			 key = "dailyIncome";
		 model.put("countedTime", DateUtil.formatDate("yyyy.MM.dd", new Date()));
		 model.put("countedUser", user.getName());
		 if(StringUtils.isNotBlank(reportParam.getReportName())){
			 key = reportParam.getReportName();
		 }
		 reportParam.setReportName(key);
		 model.put("reportParam", reportService.queryData(reportParam));
		 return "report/report_"+key;
	 }
	 
	/**
	 * 分页查询统计
	 * @param reportParam
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月11日
	 */
	@RequestMapping(value="/home",method=RequestMethod.POST)
	@ResponseBody
	public ReportSearchParam home(ReportSearchParam reportParam) throws RDPException {
		return reportService.queryData(reportParam);
	}
	
	/**
	 * 统计导出
	 * @param reportParam
	 * @param session
	 * @return
	 * @throws RDPException
	 * @date: 2014年9月11日
	 */
	@RequestMapping(value="/export")
	public void export(ReportSearchParam reportParam,HttpServletResponse response) throws RDPException {
		reportService.reportExport(reportParam,response);
	}
}
